'use strict';
import React from 'react';
import {
    View,
    Text,
    TextInput,
    TouchableOpacity,
    ActivityIndicator
} from 'react-native';
import ToolBar from '../Components/ToolBar';
import Toast from '../Utils/toast';
import FoundAPIService from '../Commom/FoundAPIService';
import Global from '../Commom/GlobalConst';
class InitiatedQuestion extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            content: '',
            money: '',
            submitting:false,
        }
    }

    componentWillUnMount() {
    }


    initatedQuestion() {
        TextInput.State.blurTextInput(TextInput.State.currentlyFocusedField());
        if (this.state.content.length == 0) {
            Toast.show("请输入问题内容");
            return;
        }
        let reward = '';
        if (this.state.money.length == 0) {
            reward = '0';
        } else {
            reward = this.state.money;
        }
        this.setState({
            submitting: true,
        });
        FoundAPIService.initiatedQuestionAnswer(Global.Const.token, Global.Const.registeredId, reward, this.state.content).then((ret)=> {
            this.setState({
                submitting: false,
            });
            Toast.show("发布成功");
            this.props.navigator.pop();

        }).catch((err)=> {
            this.setState({
                submitting: false,
            });
        });
    }

    render() {
        return (
            <TouchableOpacity activeOpacity={1} style={{flex: 1}} onPress={() => {
                TextInput.State.blurTextInput(TextInput.State.currentlyFocusedField())
            }}>
                <View style={{flex: 1, backgroundColor: '#F2F3F5'}}>
                    <ToolBar
                        leftFunc={()=> {
                            this.props.navigator.pop();
                        }}
                        title="发起有问必答"
                        rightFunc={()=> {
                          this.initatedQuestion();
                        }}
                        rightImage={require('../../Image/release_icon.png')}
                    />
                    <View style={{height:50, backgroundColor: 'white',justifyContent:'center'}}>
                        <Text style={{
                        padding: 15,
                        backgroundColor: 'white'
                    }}>问题</Text>
                    </View>

                    <TextInput
                        placeholder={'请填写问题'}
                        style={{
                            padding: 15,
                            marginTop: 1,
                            marginBottom: 1,
                            backgroundColor: 'white',
                            height: 180,
                            lineHeight: 30,
                            fontSize: 14,
                        }}
                        value={this.state.content}
                        onChangeText={content => this.setState({ content })}
                        textAlignVertical={'top'}
                        underlineColorAndroid={'rgba(0,0,0,0)'}
                        multiline={true}
                    />

                </View>
                {this.state.submitting ? <View
                    style={{position: 'absolute',top:0,left:0,width:Global.Const.size.width,height:Global.Const.size.height,backgroundColor:null,alignItems:'center',justifyContent:'center'}}>
                    <View
                        style={{backgroundColor:'#333333',borderRadius:5, alignItems: 'center',justifyContent: 'center',width:80,height:80}}>
                        <ActivityIndicator
                            animating={this.state.animating}
                            style={{ alignItems: 'center',justifyContent: 'center'}}
                            size="large"/>
                        <Text style={{color:'white'}}>正在提交</Text>
                    </View>
                </View> : null}
            </TouchableOpacity>
        )
    }
}
// <View style={{
//                         flexDirection: 'row',
//                         padding: 15,
//                         justifyContent: 'space-between',
//                         backgroundColor: 'white',
//                         alignItems: 'center'
//                     }}>
//     <Text>打赏金额</Text>
//     <TextInput
//         placeholder={'请填写打赏金额'}
//         underlineColorAndroid={'rgba(0,0,0,0)'}
//         keyboardType={'numeric'}
//         style={{
//                                 color: 'black',
//                                 backgroundColor: 'white',
//                                 flex: 1,
//                                 textAlign: 'right',
//                                 fontSize: 14
//                             }}
//         maxLength={10}
//         value={this.state.money}
//         onChangeText={money => this.setState({ money })}
//     />
// </View>
export default InitiatedQuestion;